//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.Caching;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Globalization;
using Tathata.Common.DAL;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.DAL.Managers;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Manufacturer template manager
    /// </summary>
    public class ManufacturerTemplateManager
    {
        #region Constants
        private const string MANUFACTURERTEMPLATES_ALL_KEY = "Nop.manufacturertemplate.all";
        private const string MANUFACTURERTEMPLATES_BY_ID_KEY = "Nop.manufacturertemplate.id-{0}";
        #endregion

        #region Methods
        /// <summary>
        /// Deletes a manufacturer template
        /// </summary>
        /// <param name="ManufacturerTemplateID">Manufacturer template identifier</param>
        public static void DeleteManufacturerTemplate(int ManufacturerTemplateID)
        {
            ManufacturerTemplateDBManager.DeleteManufacturerTemplate(ManufacturerTemplateID);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(MANUFACTURERTEMPLATES_ALL_KEY);
                NopCache.RemoveByPattern(MANUFACTURERTEMPLATES_BY_ID_KEY);
            }
        }

        /// <summary>
        /// Gets all manufacturer templates
        /// </summary>
        /// <returns>Manufacturer template collection</returns>
        public static ManufacturerTemplateCollection GetAllManufacturerTemplates()
        {
            string key = string.Format(MANUFACTURERTEMPLATES_ALL_KEY);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (ManufacturerTemplateCollection)obj2;
            }

            ManufacturerTemplateCollection manufacturerTemplateCollection = ManufacturerTemplateDBManager.GetAllManufacturerTemplates();
            if (NopContext.IsCachable)
            {
                NopCache.Max(key, manufacturerTemplateCollection);
            }
            return manufacturerTemplateCollection;
        }

        /// <summary>
        /// Gets a manufacturer template
        /// </summary>
        /// <param name="ManufacturerTemplateID">Manufacturer template identifier</param>
        /// <returns>Manufacturer template</returns>
        public static ManufacturerTemplate GetByManufacturerTemplateID(int ManufacturerTemplateID)
        {
            string key = string.Format(MANUFACTURERTEMPLATES_BY_ID_KEY, ManufacturerTemplateID);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (ManufacturerTemplate)obj2;
            }

            ManufacturerTemplate manufacturerTemplate = ManufacturerTemplateDBManager.GetByManufacturerTemplateID(ManufacturerTemplateID);

            if (NopContext.IsCachable)
            {
                NopCache.Max(key, manufacturerTemplate);
            }
            return manufacturerTemplate;
        }

        /// <summary>
        /// Inserts a manufacturer template
        /// </summary>
        /// <param name="Name">The manufacturer template identifier</param>
        /// <param name="TemplatePath">The template path</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>Manufacturer template</returns>
        public static ManufacturerTemplate InsertManufacturerTemplate(string Name, string TemplatePath,
            int DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn)
        {
            ManufacturerTemplate manufacturerTemplate = ManufacturerTemplateDBManager.InsertManufacturerTemplate(Name, TemplatePath,
             DisplayOrder, CreatedOn, UpdatedOn);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(MANUFACTURERTEMPLATES_ALL_KEY);
                NopCache.RemoveByPattern(MANUFACTURERTEMPLATES_BY_ID_KEY);
            }
            return manufacturerTemplate;
        }

        /// <summary>
        /// Updates the manufacturer template
        /// </summary>
        /// <param name="ManufacturerTemplateID">Manufacturer template identifer</param>
        /// <param name="Name">The manufacturer template identifier</param>
        /// <param name="TemplatePath">The template path</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>Manufacturer template</returns>
        public static ManufacturerTemplate UpdateManufacturerTemplate(int ManufacturerTemplateID, string Name, string TemplatePath,
            int DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn)
        {
            ManufacturerTemplate manufacturerTemplate = ManufacturerTemplateDBManager.UpdateManufacturerTemplate(ManufacturerTemplateID, Name, TemplatePath,
             DisplayOrder, CreatedOn, UpdatedOn);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(MANUFACTURERTEMPLATES_ALL_KEY);
                NopCache.RemoveByPattern(MANUFACTURERTEMPLATES_BY_ID_KEY);
            }
            return manufacturerTemplate;
        }
        #endregion
    }
}
